#ifndef __OBJECT_DIR__
#define __OBJECT_DIR__

/*

  Directory of the objects which are on disk or in cloud.

  The logical format is:

  | Object name (including version no) | Disk Cache | Cloud |
  
  It solves multiple purposes:
  - Avoids the need to go to disk for finding the latest version
  - Keeps a check on dirty objects in disk cache (which objects in the
    disk cache are not there in the cloud)

  The directory is populated at the time the filesystem starts. This is
  done by going scanning the local cache, and listing all the objects 
  from the cloud.

  There are only two ways a new object can get into the disk cache, either
  it is fetched from the cloud, or it is written by some local program
  through the fuse layer (by using put_object)

  Precautions:
  - There can be race conditions here. So proper locking is required.
  - This can become HUGE, and is called frequently. So fast is desirable.

  We just keep adding objects to the directory, because we never delete
  anything from the local cache once the filesystem is executing.
  We have infinite local disk ...Lol

  Also, an object, once synced, will never be out of sync again. Ever !!!

*/

void dump_object_dir ();

/* 
  Initializes the object directory. This is to be called in the init 
  function of the file system.
*/
void init_object_dir();

/*
  Adds a new object to the directory.
  This can be either because 
  - A new object was created locally, which will be written to disk first
  - A new object appeared in the cloud
*/
void add_to_object_dir (const char *object_name);

/* Set the attributes */
void set_disk_field (const char *object_name, int disk);
void set_cloud_field (const char *object_name, int cloud);

/* Get the attributes */
int get_disk_field (const char *object_name);
int get_cloud_field (const char *object_name);

/* 
  Performs a prefix search, and puts the object_names appeared as 
  a result into buf, which has a max size of MAX_LENGTH bytes.

  Note that the names need not be sorted. Returns the number of names
*/
int prefix_search (const char *prefix, int max_length, char *buf);

#endif /* __OBJECT_DIR__ */
